package lab;

public class Liczba{
	private int data;
	public Liczba(){
		data = 0;
	}
	public void set(String s, int b){
		data = 0;
		int pow = 1;
		for(int i=s.length()-1; i>=0; i--){
			char c = s.charAt(i);
			if(c >= '0' && c <= '9')
				data += (c-'0')*pow;
			else{
				c &= ~(1<<5);
				data += (c-'A'+10)*pow;
			}
			pow *= b;
		}
	}
	public String get(int b){
		if(b<2 || b>17)
			return null;
		int n = data;
		char[] buffer = new char[256];
		int i = 255;
		while(n > 0){
			int a = n%b;
			n /= b;
			if(a<=9)
				buffer[i--] = (char)(a+'0');
			else
				buffer[i--] = (char)(a+'A'-10);
		}
		return String.copyValueOf(buffer, i+1, 255-i);
	}
	public static void main(String[] args){
		Liczba l = new Liczba();
		l.set("ffff", 16);
		System.out.println(l.get(10));
		System.out.println(l.get(16));
		System.out.println(l.get(8));
	}

}
